package cn.yitun.chat.yitunserverimcore.general.main.push.group;

import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.group.GroupMemberPushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import cn.yitun.chat.yitunserverimcore.general.common.util.PushMessageBuild;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 群成员相关推送
 * Date 2019-01-27 21:43:21<br>
 * Description
 * 
 * @author yitun<br>
 * @version 1.1
 */
@Service
public class GroupMemberPush {
	//1.2.204
	final String action = ActionTypeConstant.GROUP_MEMBER_ACTION_PUSH;

	@Resource
	WriteHandler writeHandler;

	/**
	 * 添加
	 * @param groupId
	 * @param userId
	 * @param userIdList
	 */
	public void pushAdd(Long groupId, Long userId, List<Long> userIdList) {
		String method = GroupMemberPushMethodEnum.ADD.getMethod();
		PushMessage message = PushMessageBuild.build(action, method);
		message.bodyPut("userId", userId);
		message.bodyPut("groupId", groupId);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}

	/**
	 * 更新详情
	 * @param groupId
	 * @param userId
	 * @param userIdList
	 */
	public void pushUpdate(Long groupId, Long userId, List<Long> userIdList) {
		String method = GroupMemberPushMethodEnum.UPDATE_INFO.getMethod();
		PushMessage message = PushMessageBuild.build(action, method);
		message.bodyPut("userId", userId);
		message.bodyPut("groupId", groupId);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}

	/**
	 * 更新职位
	 * @param groupId
	 * @param userId
	 * @param position
	 * @param userIdList
	 */
	public void pushUpdatePosition(Long groupId, Long userId, String position, List<Long> userIdList) {
		String method = GroupMemberPushMethodEnum.UPDATE_POSITION.getMethod();
		PushMessage message = PushMessageBuild.build(action, method);
		message.bodyPut("userId", userId);
		message.bodyPut("position", position);
		message.bodyPut("groupId", groupId);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}

	/**
	 * 删除
	 * @param groupId
	 * @param userId
	 * @param userIdList
	 */
	public void pushDelete(Long groupId, Long userId, List<Long> userIdList) {
		String method = GroupMemberPushMethodEnum.REMOVE.getMethod();
		PushMessage message = PushMessageBuild.build(action, method);
		message.bodyPut("userId", userId);
		message.bodyPut("groupId", groupId);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}
//	/**
//	 * 删除
//	 * @param groupId
//	 * @param list
//	 * @param userIdList
//	 */
//	public void pushDelete(Long groupId, List<GroupMemberVo> list, List<Long> userIdList) {
//		String method = GroupMemberPushMethodEnum.SET_LIST.getMethod();
//		PushMessage message = PushMessageBuild.build(action, method);
//		message.bodyPut("list", list);
//		message.bodyPut("groupId", groupId);
//		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
//	}
}
